package com.xbao.controller;

import com.xbao.core.component.page.Pagination;
import com.xbao.core.http.CommRequest;
import com.xbao.core.http.CommResult;
import com.xbao.model.Subject;
import com.xbao.model.req.StuReq;
import com.xbao.model.req.SubjectReq;
import com.xbao.model.vo.StuVo;
import com.xbao.model.vo.SubjectVo;
import com.xbao.service.SubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by qingshengzheng on 18/8/25.
 */
@Api(value = "/subject", tags = "subject")
@RequestMapping(value = "subject")
@Controller
@EnableAutoConfiguration
public class SubjectController extends BaseController {
    @Resource
    private SubjectService subjectService;

    /**
     */
    @ApiOperation(value = "addSubject", notes = "addSubject")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Object addSubject(@RequestBody CommRequest<SubjectReq> balanceTypeCommRequest) {
        subjectService.addSubject(balanceTypeCommRequest.getData());
        return result();
    }
    @ApiOperation(value = "updateSubject", notes = "updateSubject")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Object updateSubject(@RequestBody CommRequest<SubjectReq> subjectReqCommRequest) {
        subjectService.modifySubject(subjectReqCommRequest.getData());
        return result();
    }


    @ApiOperation(value = "queryByTag", notes = "queryByTag")
    @RequestMapping(value = "/queryByTag",method = RequestMethod.POST)
    @ResponseBody
    public Object queryByTag(@RequestBody CommRequest<SubjectReq> balanceTypeCommRequest) {
        subjectService.addSubject(balanceTypeCommRequest.getData());
        return result();
    }
    /**
     * @param subjectReqCommRequest
     * @return
     */
    @ApiOperation(value = "deleteSubject", notes = "deleteSubject")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Object deleteSubject(@RequestBody CommRequest<SubjectReq> subjectReqCommRequest) {
        subjectService.deleteSubject(subjectReqCommRequest.getData().getId());
        return result();
    }

    /**
     * @param subjectReqCommRequest
     * @return
     */
    @ApiOperation(value = "detailSubject", notes = "detailSubject")
    @RequestMapping(value = "/detail",method = RequestMethod.POST)
    @ResponseBody
    public Object detailSubject(@RequestBody CommRequest<SubjectReq> subjectReqCommRequest) {
        SubjectVo vo=subjectService.detailSubject(subjectReqCommRequest.getData().getId());
        return new CommResult<SubjectVo>(vo);
    }

    /**
     * @param subjectReqCommRequest
     * @return
     */
    @ApiOperation(value = "querySubjects", notes = "querySubjects")
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ResponseBody
    public CommResult<List<Subject>> querySubjects(@RequestBody CommRequest<SubjectReq> subjectReqCommRequest) {
        List<Subject> subjects = subjectService.querySubjects(subjectReqCommRequest.getData());
        return new CommResult<List<Subject>>(subjects);
    }


}
